package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsTopicSection;
import com.ruoyi.system.domain.news.query.NewsTopicSectionQuery;
import com.ruoyi.system.domain.news.vo.NewsTopicSectionVo;
import com.ruoyi.system.service.news.NewsTopicSectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsTopicSection")
@Api(value = "newsTopicSectionApiController", tags  = "专题专栏Api")
public class NewsTopicSectionApiController extends BaseController {

	@Resource
	private NewsTopicSectionService newsTopicSectionService;

	@ApiOperation(value = "获取单个专题专栏信息", notes = "获取单个专题专栏信息")
	@GetMapping("/getById")
	public R<NewsTopicSection> getById(@RequestParam(value = "id") Long id) {
		NewsTopicSectionQuery newsTopicSectionQuery = new NewsTopicSectionQuery();
		newsTopicSectionQuery.setId(id);
		List<NewsTopicSectionVo> newsTopicSectionList = newsTopicSectionService.getNewsTopicSectionList(newsTopicSectionQuery);
		if (newsTopicSectionList!=null&&newsTopicSectionList.size()>0) {
			return R.ok(newsTopicSectionList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取专题专栏信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsTopicSectionVo>> list(@RequestBody NewsTopicSectionQuery newsTopicSectionQuery) {
        newsTopicSectionQuery.setIsEnable("1");
		List<NewsTopicSectionVo> newsTopicSectionList = newsTopicSectionService.getNewsTopicSectionList(newsTopicSectionQuery);
		return R.ok(new PageInfo<>(newsTopicSectionList));
	}
}
